# 辅助数据结构生成

from collections import Counter
from process.ReadFile import poetrys

all_words = []
for poetry in poetrys:
    all_words += [word for word in poetry]
counter = Counter(all_words)   # 对所有字符进行计数
count_pairs = sorted(counter.items(), key=lambda x: -x[1])  # 对计数结果进行排序，并返回一个tuple
words, _ = zip(*count_pairs)  # 对tuple进行解压，得到words列表代表所有字符，该字符的行号即为该字符索引
words = words[:len(words)] + ('',)
word_num_map = dict(zip(words, range(len(words))))  # 得到字符与行号对应的索引字典
to_num = lambda word: word_num_map.get(words, len(words))
poetry_vector = [list(map(to_num, poetry)) for poetry in poetrys]  # 将字符数据集映射成为索引
# print('all-words', counter)
print(poetry_vector[1])

